import 'package:flutter/material.dart';
import 'package:lx_widgets_library/config.dart';
import '../const/color.dart';
import 'button_type.dart';

/*
 * 按钮颜色模型
*/
class ButtonTypeColor {
  Color backgroundColor = LxWidgetsLibraryService.to.colorType.color6;
  Color textColor = WhiteColor.white1;
  Color borderColor = LxWidgetsLibraryService.to.colorType.color6;
  Color clickColor = LxWidgetsLibraryService.to.colorType.color7.withOpacity(0.3);
}

class ButtonTypeDefaultColor extends ButtonTypeColor {
  // 按钮样式
  final ButtonTypeEnum? buttonTypeEnum;

  // 按钮状态
  final ButtonStausEnum? buttonStausEnum;

  // 按钮权重
  final ButtonWeightEnum? buttonWeightEnum;

  // 是否禁用
  bool get disable => buttonStausEnum == ButtonStausEnum.disable;

  // 初始化
  ButtonTypeDefaultColor({
    this.buttonTypeEnum = ButtonTypeEnum.base,
    this.buttonWeightEnum = ButtonWeightEnum.primary,
    this.buttonStausEnum = ButtonStausEnum.normal,
  }) {
    backgroundColor = _backgroundColor;
    textColor = _textColor;
    borderColor = _borderColor;
    clickColor = _clickColor;
  }

  Color get _backgroundColor {
    switch (buttonWeightEnum!) {
      case ButtonWeightEnum.primary:
        return disable ? disabledColor : LxWidgetsLibraryService.to.colorType.color6;
      case ButtonWeightEnum.defaulT:
        return disable ? disabledColor : GrayColor.gray3;
    }
  }

  Color get _textColor {
    switch (buttonWeightEnum!) {
      case ButtonWeightEnum.primary:
        switch (buttonTypeEnum!) {
          case ButtonTypeEnum.base:
            return disable ? WhiteColor.white4 : WhiteColor.white1;
          default:
            return disable ? LxWidgetsLibraryService.to.colorType.color3 : LxWidgetsLibraryService.to.colorType.color6;
        }
      case ButtonWeightEnum.defaulT:
        return disable ? WhiteColor.white4 : WhiteColor.white1;
    }
  }

  Color get _borderColor {
    switch (buttonWeightEnum!) {
      case ButtonWeightEnum.primary:
        switch (buttonTypeEnum!) {
          case ButtonTypeEnum.base:
            return disable ? Colors.transparent : backgroundColor;
          case ButtonTypeEnum.text:
            return Colors.transparent;
          case ButtonTypeEnum.outline:
            return disable ? disabledColor : LxWidgetsLibraryService.to.colorType.color6;
        }
      case ButtonWeightEnum.defaulT:
        switch (buttonTypeEnum!) {
          case ButtonTypeEnum.base:
            return backgroundColor;
          case ButtonTypeEnum.text:
            return Colors.transparent;
          case ButtonTypeEnum.outline:
            return disable ? disabledColor : GrayColor.gray4;
        }
    }
  }

  Color get _clickColor {
    switch (buttonStausEnum!) {
      case ButtonStausEnum.disable:
        return Colors.transparent;
      default:
        switch (buttonWeightEnum!) {
          case ButtonWeightEnum.primary:
            return LxWidgetsLibraryService.to.colorType.color6.withOpacity(0.3);
          case ButtonWeightEnum.defaulT:
            return GrayColor.gray5;
        }
    }
  }

  Color get disabledColor {
    switch (buttonWeightEnum!) {
      case ButtonWeightEnum.primary:
        return LxWidgetsLibraryService.to.colorType.color6.withOpacity(0.5);
      case ButtonWeightEnum.defaulT:
        return GrayColor.gray2;
    }
  }
}
